const info = document.querySelector('#info');
const inputName = document.querySelector('#inputName')
const inputPrice = document.querySelector('#inputPrice')
const inputNum = document.querySelector('#inputNum')

document.querySelector('#btn-add').onclick = function () {
    const name = inputName.value
    const price = inputPrice.value
    const num = inputNum.value
    // 取到三个值，发送给后端，完成新增
    utils.fetch('./api/v1/shop/add.php', { name, price, num }).then(resp => {
        info.className = 'text-center'
        info.innerHTML = resp.body.msg
        if (resp.code === 200) {
            info.classList.add('text-success')
            setTimeout(() => {
                info.innerHTML = ''
                // 弹框消失
                $('#addModal').modal('hide')
                // 重新获取一次最新的数据
                getData()
            }, 1500)
        } else {
            info.classList.add('text-danger')
            setTimeout(() => {
                info.innerHTML = ''
            }, 1500)
        }
    })
}

$('#addModal').on('hidden.bs.modal', function (e) {
    inputName.value = inputPrice.value = inputNum.value = ''
})

// 判断事件源的calss使用一下方法
console.log(document.querySelector('table').classList)

const classList = Array.from(document.querySelector('table').classList)

console.log(classList.includes('table-hover'))
